# -*- coding: utf-8 -*-
"""
Created on 2021-6-6 09:27:34
客户端函数
@author: 王韬
"""
import datetime
import os
import pygame
from pygame.locals import *
import socket

import classes as cls


def get_ip():
    """获取IP"""
    host = socket.gethostname()
    ip = socket.gethostbyname(host)
    # host = socket.getfqdn(socket.gethostname())
    # ip = socket.gethostbyname(host)
    return ip


def get_time():
    """获取发送时间"""
    now = datetime.datetime.now()
    send_time = now.strftime("%Y-%m-%d %H:%M:%S")
    return send_time


# ###################<<pygame func>>################### #
def load_img(name):
    """load image

    Arguments:
        name -- file name of image
    Returns:
        image -- pygame.image.convert
        image.get_rect -- rect of image
    """
    full_name = os.path.join('data', name)
    try:
        image = pygame.image.load(full_name)
        if image.get_alpha() is None:
            image = image.convert()
        else:
            image = image.convert_alpha()
    except pygame.error as e:
        print("image load err", e)
        raise SystemExit(e)
    return image, image.get_rect()

